Skip to content

drivers: Standardize read and measurement method naming.#160

Merged
nedseb merged 1 commit intomainfrom
fix/standardize-read-methods
Mar 16, 2026
Merged

drivers: Standardize read and measurement method naming.#160
nedseb merged 1 commit intomainfrom
fix/standardize-read-methods

Conversation

@nedseb
Copy link
Copy Markdown
Contributor

@nedseb nedseb commented Mar 15, 2026

Closes #80

Summary

Standardize measurement method naming across all drivers.

Convention:

  • temperature(), humidity() — bare noun, no unit suffix (°C and %RH are unambiguous)
  • All other measurements include the unit: pressure_hpa(), distance_mm(), voltage_mv(), acceleration_g(), etc.
  • read() — combined reading returning a tuple
  • <measurement>_raw() — raw register values
  • No read_ prefix on individual measurements

Changes

Driver Before After
hts221 get() removed (duplicate of read())
lis2mdl read_temperature_c() temperature()
lis2mdl read_magnet() magnetic_field()
lis2mdl read_magnet_raw() magnetic_field_raw()
lis2mdl read_magnet_uT() magnetic_field_ut()
lis2mdl read_magnet_calibrated_norm() calibrated_field()
lis2mdl magnitude_uT() magnitude_ut()
apds9960 read_ambient_light() ambient_light()
apds9960 read_red/green/blue_light() red/green/blue_light()
apds9960 read_proximity() proximity()
apds9960 read_gesture() gesture()
vl53l1x read() only + distance_mm() as primary, read() as alias
wsen-pads pressure() pressure_hpa()
bq27441 voltage() voltage_mv()

Final state

Driver Combined Individual
hts221 read() → tuple temperature(), humidity()
ism330dl acceleration_g(), acceleration_ms2(), gyroscope_dps(), gyroscope_rads(), temperature_c()
lis2mdl magnetic_field(), magnetic_field_ut(), magnetic_field_raw(), calibrated_field(), temperature(), magnitude_ut()
vl53l1x read() (alias) distance_mm()
wsen-hids read() → tuple temperature(), humidity()
wsen-pads read() → tuple temperature(), pressure_hpa(), pressure_kpa()
apds9960 ambient_light(), red_light(), green_light(), blue_light(), proximity(), gesture()
bq27441 voltage_mv(), temperature(), soc()

Also updated README, tests, examples, and driver READMEs.

Test plan

ruff check lib/                          # All checks passed
python3 -m pytest tests/ -k "mock" -v    # 115 passed

@nedseb nedseb requested a review from Copilot March 15, 2026 14:47
@nedseb nedseb self-assigned this Mar 15, 2026
@nedseb nedseb added the enhancement New feature or request label Mar 15, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Standardizes sensor measurement method naming across several drivers to follow a consistent “bare noun” API and updates scenarios/examples/docs accordingly (per #80).

Changes:

  • Renames LIS2MDL temperature API from read_temperature_c() to temperature() and updates related tests/examples/docs.
  • Renames APDS9960 measurement methods from read_* to bare nouns (ambient_light(), proximity(), gesture(), etc.) and updates tests/examples/docs.
  • Removes HTS221 get() (duplicate of read()) and documents the measurement naming convention in the root README.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/scenarios/lis2mdl.yaml Updates scenario calls to temperature()
tests/scenarios/board_temperature_comparison.yaml Updates LIS2MDL temperature usage in board comparison script
tests/scenarios/apds9960.yaml Updates scenario calls to APDS9960 bare-noun measurement methods
lib/lis2mdl/lis2mdl/device.py Renames read_temperature_c()temperature() and updates internal usage
lib/lis2mdl/examples/magnet_test.py Updates example to call temperature()
lib/lis2mdl/README.md Updates LIS2MDL README to reference temperature()
lib/hts221/hts221/device.py Removes get() wrapper around read()
lib/apds9960/examples/proximity.py Updates example to call proximity()
lib/apds9960/examples/gesture.py Updates example to call gesture()
lib/apds9960/examples/ambient_light.py Updates example to call ambient_light()
lib/apds9960/apds9960/device.py Renames read_* methods to bare nouns
README.md Updates APDS9960 usage example and documents measurement naming convention

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread README.md Outdated
- **Reset methods**: `reset()` for hardware reset (pin toggle), `soft_reset()` for software reset (register write), `reboot()` for memory reboot (reload trimming).
- **Power methods**: `power_on()` / `power_off()`. All drivers must implement both.
- **Status methods**: `_status()` returns the raw status register as an int (private), `data_ready()` returns True when all channels have new data, `<measurement>_ready()` for per-channel readiness (e.g. `temperature_ready()`, `pressure_ready()`).
- **Measurement methods**: bare noun for the main unit (`temperature()`, `humidity()`, `pressure()`), `read()` for combined reading returning a tuple, `<measurement>_raw()` for raw register values. No `read_` prefix on individual measurements.
Comment on lines 248 to +252
hi = self._read_reg(LIS2MDL_TEMP_OUT_H_REG)
v = (hi << 8) | lo
return v - 0x10000 if (v & 0x8000) else v

def read_temperature_c(self) -> float:
def temperature(self) -> float:
Comment on lines 191 to 195
delta = float(measured_high - measured_low)
if delta == 0.0:
raise ValueError("measured_low and measured_high must differ")
self._temp_gain = float(ref_high - ref_low) / delta
self._temp_offset = float(ref_low) - self._temp_gain * float(measured_low)
@@ -169,7 +169,7 @@ def is_gesture_available(self):
return val == APDS9960_BIT_GVALID

# processes a gesture event and returns best guessed gesture
@nedseb nedseb force-pushed the fix/standardize-read-methods branch 2 times, most recently from e3ac1cb to 6cf63d9 Compare March 15, 2026 14:57
@nedseb nedseb force-pushed the fix/standardize-read-methods branch from 6cf63d9 to be4f22e Compare March 15, 2026 15:22
@nedseb nedseb merged commit ad194c9 into main Mar 16, 2026
4 checks passed
@nedseb nedseb deleted the fix/standardize-read-methods branch March 16, 2026 08:51
@semantic-release-updater
Copy link
Copy Markdown

🎉 This PR is included in version 0.0.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

drivers: Standardize read/measurement method naming.

2 participants